/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package czStvDpds.network;

import czStvDpds.logging.Logging;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Xide
 */
public class Sender {

    protected DatagramSocket datagramSocket;
    public int SENDING_PORT = 9877;
    public InetAddress addressOfServer;
    public boolean potvrzeni;    
    private String zprava;
   


    public Sender(InetAddress address) {
        addressOfServer = address;
         try {
            //datagramSocket = new DatagramSocket(SENDING_PORT, addressOfServer);
            datagramSocket = new DatagramSocket();
        } catch (SocketException ex) {
            System.out.println("socket failed");
            Logging.getMainLogger().log(Level.SEVERE, ex.getLocalizedMessage());
        }
    }

    

    

    protected void ukonciSpojeni() {
        datagramSocket.close();
    }

    protected void sendPacket(DatagramPacket g) {
        try {
            

           /* byte bajt[] = new byte[g.getLength()];
             bajt = g.getData();
             String zprava = new String(bajt);*/          
         
            g.setAddress(addressOfServer);
            g.setPort(SENDING_PORT);
            datagramSocket.send(g);
            
            Logging.getMainLogger().log(Level.SEVERE, "Potvrzovaci PaketOdeslan");
        } catch (IOException ex) {
            Logger.getLogger(Sender.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
